<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户信息</title>
<%@ include file="../../common/common.jsp"%>

</head>
<script type="text/javascript">

//新增用户
function newCp_info(){
	$('#dlg').dialog('open').dialog('setTitle', '新增用户');
	jQuery('#companyCode').combobox({
	    url:'<%=basePath%>jsp/GetJson.jsp?type=companyinfoList',
	    valueField:'companyCode',
	    textField:'companyName'
	});
	jQuery('#extend1').combobox({
	    url:'<%=basePath%>js/qn/userType.json',
	    valueField:'value',
	    textField:'text'
	});
	$('#fm').form('clear');
}
//编辑用户信息
function editCp_info() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$('#dlg').dialog('open').dialog('setTitle', '编辑用户');
		jQuery('#companyCode').combobox({
		    url:'<%=basePath%>jsp/GetJson.jsp?type=companyinfoList',
		    valueField:'companyCode',
		    textField:'companyName'
		});
		$('#companyCode').combobox('setText',row.companyCode);
		jQuery('#extend1').combobox({
		    url:'<%=basePath%>js/qn/userType.json',
		    valueField:'value',
		    textField:'text'
		});
		$('#extend1').combobox('setText',row.extend1);
		$('#fm').form('load', row);
	}
}

//保存用户信息
function saveCp_info() {
	$('#fm').form('submit', {
		url : '<%=basePath%>saveUserinfoAction!saveData.do',
		onSubmit : function() {
			return $(this).form('validate');
		},
		success : function(result) {
			var result = eval('(' + result + ')');
			//alert(result);
			if (result.message=='success') {
				$('#dlg').dialog('close'); // close the dialog
				$('#dg').datagrid('reload'); // reload the user data
		} else {
		$.messager.show( {
			title : '错误提示',
			msg : result.message
		});
	}
}
	});
}



function removeCp_info() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$.messager.confirm('Confirm',
				'请确认是否删除该用户信息?', function(r) {
					if (r) {
						$.post('<%=basePath%>saveUserinfoAction!destoryData.do', {
							id : row.id
						}, function(result) {
							if (result.message=='success') {
								$('#dg').datagrid('reload'); // reload the user data
							} else {
								$.messager.show( { // show error message
										title : '错误提示',
										msg : result.message
										});
							}
						}, 'json');
					}
				});
	}
}
</script>
<body>
	<table id="dg" title="用户信息" class="easyui-datagrid"
		style="width: 1000px; height: 370px"
		url="<%=basePath%>jsp/GetJson.jsp?type=userinfoList"
		toolbar="#toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true">
		<thead>
			<tr>
				<th field="useraccount" width="20">用户帐号</th>
				<th field="username" width="30">用户名字</th>
				<th field="usertype" width="30" >用户角色</th>
				<th field="companyName" width="30">所属机构</th>
				<th field="action" width="30">分配权限</th>
				<th field="companyCode" width="30" hidden='true'></th>
			</tr>
		</thead>
	</table>


	<div id="toolbar">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
			onclick="newCp_info()">新建</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editCp_info()">编辑</a> <a
			href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true"
			onclick="removeCp_info()">删除</a>
	</div>

	<div id="dlg" class="easyui-dialog"
		style="width: 600px; height: 280px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons">
		<div class="ftitle">用户信息</div>
		<form id="fm" method="post">
			<table>

				<tr colspan="2" style="display: none">

					<td>
						<div class="fitem">
							<label> ID: </label> <input name="id" class="easyui-validatebox">
						</div></td>

				</tr>

				<tr height="50px">
					<td>
						<div class="fitem">
							<label> 用户帐号: </label> <input name="useraccount"
								class="easyui-validatebox" required="true">
						</div></td>
						 
					<td > 
						<div class="fitem" style="margin-left: 50px;">
							<label> 所属机构: </label>
							<!-- <input name="companyCode" class="easyui-validatebox" required="true">-->
							<select id="companyCode" class="easyui-combotree"
								name="companyCode" style="width: 133px;"></select>
						</div></td>
				</tr>
				
				<tr  height="50px">
					<td>
						<div class="fitem">
							<label> 用户名字: </label> <input name="username"
								class="easyui-validatebox" required="true">
						</div></td>
						
						<td>
						<div class="fitem" style="margin-left: 50px;">
							<label> 用户角色: </label> 
								<select id="usertype" class="easyui-combotree"
								name="usertype" style="width: 133px;"></select>
						</div></td>
				</tr>

			</table>

		</form>
	</div>
	<div id="dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="saveCp_info()">Save</a> <a href="#"
			class="easyui-linkbutton" iconCls="icon-cancel"
			onclick="javascript:$('#dlg').dialog('close')">Cancel</a>
	</div>
</body>
</html>